package com.teach.food.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.dto.FoodOrderDTO;
import com.teach.entity.Comments;
import com.teach.exception.CodeException;
import com.teach.food.dto.FoodOrderInfoSearch;
import com.teach.food.entity.FoodOrderInfo;
import com.teach.mapper.FoodOrderInfoMapper;
import com.teach.food.service.FoodOrderInfoService;
@Service
public class FoodOrderInfoServiceImpl implements FoodOrderInfoService{
	@Autowired
	private FoodOrderInfoMapper mapper;

	@Override
	public List<FoodOrderInfo> selectWeek(String date,String name) {
		return mapper.statementWeek(date,name);
	}

	@Override
	public List<FoodOrderInfo> selectMonth(String date,String name) {
		return mapper.statementMonth(date,name);
	}

	@Override
	public List<FoodOrderInfo> commentsAllList(FoodOrderInfoSearch foodOrdersrInfoDTO) throws CodeException {
		return mapper.selectAll(foodOrdersrInfoDTO);
	}

	@Override
	public List<FoodOrderInfo> list(int startIndex, int len) {
		PageInfo<FoodOrderInfo> pageInfo = PageHelper.offsetPage(startIndex, len).setCount(false).doSelectPageInfo(()->mapper.selectAll(null));
		return pageInfo.getList();
	}

	@Override
	public PageInfo<FoodOrderInfo> page(int current, int rowMax) {
		return PageHelper.startPage(current, rowMax).doSelectPageInfo(()->mapper.selectAll(null));
	}

	@Override
	public PageInfo<FoodOrderInfo> pageSearch(FoodOrderInfoSearch FoodOrderInfoDTO) {
		return PageHelper.startPage(FoodOrderInfoDTO.getCurrent(), FoodOrderInfoDTO.getRowMax()).doSelectPageInfo(()->mapper.selectAll(FoodOrderInfoDTO));
	}

	@Override
	public FoodOrderInfo get(Integer orderInfoId) {
		return mapper.selectByPrimaryKey(orderInfoId);
	}

	@Override
	public int delect(Integer orderInfoId) {
		mapper.deleteByPrimaryKey(orderInfoId);
		return 0;
	}

	@Override
	public int update(FoodOrderInfo orderInfo) {
		mapper.updateByPrimaryKeySelective(orderInfo);
		return 0;
	}

	@Override
	public List<FoodOrderDTO> listByuserName(String userName) {
		
		return mapper.selectByUserName(userName);
	}
	
	@Override
	public List<FoodOrderInfo> selectLastMonth(String name) {
		return mapper.statementLastMonth(name);
	}
	
}
